home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig18_08.jar / Ch18 / Fig18_08 / Fig18_08.cpp
C/C++ Source or Header  |  1997-11-10  |  536b  |  27 lines

  1. // Fig. 18.8: fig18_08.cpp
  2. // An example of a union 
  3. #include <iostream.h>
  4.  
  5. union Number {
  6.    int x;
  7.    float y;
  8. };
  9.  
  10. int main()
  11. {
  12.    Number value;
  13.     
  14.    value.x = 100;
  15.    cout << "Put a value in the integer member\n"
  16.         << "and print both members.\nint:   " 
  17.         << value.x << "\nfloat: " << value.y << "\n\n";
  18.     
  19.    value.y = 100.0;
  20.    cout << "Put a value in the floating member\n" 
  21.         << "and print both members.\nint:   " 
  22.         << value.x << "\nfloat: " << value.y << endl;
  23.    return 0;
  24. }
  25.  
  26.  
  27.